#include "file.h"
#include "../cparser/parser.h"

namespace losor
{
	file::file( string path, string name, object *parent )
		: object( "file", name, parent ),
		m_path( path )
	{
		// TODO:
	}
	
	file::~file()
	{
		// TODO:
	}
	
	long file::parse( string para, object *parent )
	{
		char *code;
		list<ppobject*> ppobj;
		list<object*> obj;
		list<object*>::iterator i;
		int nppobj = 0;
		int nobj = 0;

		code = fileutil::read( m_path, -1 );
		nppobj = pp_parser( code, ppobj );
		if( nppobj > 0 )
			nobj = parser( ppobj, obj );

		for( i = obj.begin(); i != obj.end(); ++i )
			add_child( *i );

		delete []code;
		return 0;
	}
	
	long file::write_depend( object *parent )
	{
		// TODO:
		return 0;
	}
	
	string file::path() const
	{
		return m_path;
	}
	
	void file::rm_child( string para )
	{
		// keep empty: can not remove child untill re-parse file
	}
}

